<!-- 项目设备页面 -->
<template>
    <div class="project-container">
     
      <el-card shadow="hover">
        <div class="equip-list">
         
          <div style="display: flex;align-items: center;justify-content: space-between;margin-bottom: 20px;">
            <span class="equip-title_span">安全设计审查</span>
  
            <div
            
              style="
                display: flex;
                justify-content: flex-end;
                align-items: center;
              "
            >
              <el-button-group  class="create-del-equip">

                <el-tooltip content="新建设计检查表
" placement="top" effect="dark">
<el-button
          
                  type="primary"
                  color="#626aef"
                  size="small"
                  :icon="Plus"
                  tag="新建设计检查表"
                  @click="newDioFn()"
                />
                </el-tooltip>

                <el-tooltip  content="导出安全审查表 " placement="top" effect="dark">
                  <el-button
                  class="button_mt"
                    type="primary"
                    color="#67c23a"
                    size="small"
                    :icon="Tickets"
                    tag="导出"
                    @click="clickDC"
                  />
                </el-tooltip>
             
               
              </el-button-group>
            </div>
          </div>
          
          <el-table
   
   @selection-change="handleSelectionChange"
   class="mmy-tables"
   :header-cell-style="{ background: '#fafbfc', color: '#333333' }"
   :data="tableDatas"
   style="width: 100%"
   :height="activeHeight"
 >
   <el-table-column :selectable="selectable"  type="selection" width="30" />
   <el-table-column  width='70' type="index"  label="序号" />
  
   <el-table-column prop="major"     label="专业" >
        <template  #header>
      <div style="display: flex;align-items: center;">
      <div style="margin-right: 5px;">专业 </div>
      <el-popover  :width="200"
    trigger="hover">
      
        
        <template #reference>
          <div class="icone" :class="majorSelect.length==0?'':'active'">
        <el-icon><Filter /></el-icon>
      </div>
        </template>
        <el-select-v2
      
        :teleported ='false'
           size="small"
              style="width: 180px; margin-right: 10px;z-index: 2000;"
              clearable
              multiple
              filterable
              collapse-tags
              collapse-tags-tooltip
              :options="[
                {
                  value:'粉体专业',

                label:'粉体专业'
                },
                {
                  value:'工程图',

                label:'工程图'
                },


              ]"
              v-model="majorSelect"
             
              placeholder="请选择"
              
            >
            </el-select-v2>

      </el-popover>
    </div>
      
     </template>
      
      </el-table-column>
   <el-table-column show-overflow-tooltip prop="check_content"   label="检查内容">
    <template  #header>
      <div style="display: flex;align-items: center;">
      <div style="margin-right: 5px;">检查内容 </div>
      <el-popover  :width="200"
    trigger="hover">
      
        
        <template #reference>
          <div class="icone" :class="majorSelect.length==0?'':'active'">
        <el-icon><Filter /></el-icon>
      </div>
        </template>
      
            <el-input :teleported ='false'
            size="small"
             style="width: 180px; margin-right: 10px;z-index: 2000;"
             v-model="check_contentSelect"
             
              placeholder="请输入"
             ></el-input>

      </el-popover>
    </div>
      
     </template>
    
   </el-table-column>
   <el-table-column prop="checker"   label="审核人">
    <template #default="{ row }">
       <el-tag type="success">{{row.checker}}</el-tag>
    </template>
   </el-table-column>
   <el-table-column prop="sender"   label="派发人">
    <template #default="{ row }">
       <el-tag type="danger">{{row.sender}}</el-tag>
    </template>

   </el-table-column>
   <el-table-column prop="check_status"   label="审核状态">
    <template #default="{ row }">
      <div v-if="!row.check_status" style="display: flex;align-items: center">
        <div style="width: 10px;height: 10px;background-color: #f56c6c;border-radius: 50%;margin-right: 10px;"></div>
        <span>未审核</span>
      </div>
      <div v-if="row.check_status" style="display: flex;align-items: center">
        <div style="width: 10px;height: 10px;background-color: #67c23a;border-radius: 50%;margin-right: 10px;"></div>
        <span>审核通过</span>
      </div>
    </template>

   </el-table-column>
   <el-table-column prop="create_time"   label="派发时间"/>
   <el-table-column fixed="right" label="操作" width="150" align="center">
     <template #default="{ row }">
       <el-button
        
         link
         type="primary"
         size="small"
         @click="checkDetail(row)"
         >查看详情</el-button
       >

       <el-popconfirm
      
         placement="left"
         @confirm="deleteRow(row)"
         title="确定要删除?"
       >
         <template #reference>
           <el-button  link type="danger" size="small">删除</el-button>
         </template>
       </el-popconfirm>
     </template>
   </el-table-column>
 </el-table>
        </div>
      </el-card>
  
      <el-dialog
      @close="cancelButtonText(newDioFromRef)"
      :close-on-click-modal="false"
      title="新建粉体专业设计表"
        v-model="newDio"
        width="25%"
      >
      <div class="new-dio-container">
        <el-form
         :rules="newDioFromRules"
          size="small"
          :model="newDioFrom"
          label-width="90px"
          label-position="left"
        
          ref="newDioFromRef"
        >
          <el-form-item label="专业名称：" prop="proName">
           <el-select-v2
            disabled
           style="width:100%"
            v-model="newDioFrom.proName"
            placeholder="请选择专业名称"
          
            :options="[
             
              {
                value:'粉体专业',
                label:'粉体专业'
              },
             

            ]"
            
           >
           </el-select-v2>

           

          </el-form-item>

          <el-form-item label="审查人：" prop="checkers">
            <el-select  :filter-method="matchFruit" style="width: 100%;" collapse-tags-tooltip collapse-tags  placeholder="请选择" size="small"  filterable clearable v-model="newDioFrom.checkers">
        <el-option v-for="(item,index) in sendDataCheckOptions_py"  :key="index" :label="item.label" :value="item.value">
 
        </el-option>
      </el-select>

           

          </el-form-item>

        

          <el-form-item>
            <div style="width: 100%; display: flex; flex-direction: row-reverse">
              <el-button
              type="primary"
              size="small"
              @click="newDioFnSubmit(newDioFromRef)"
              >确定</el-button
            >
            &nbsp;&nbsp;&nbsp;&nbsp;
            <el-button size="small" @click="cancelButtonText(newDioFromRef)">取消</el-button>
          


            </div>
           
            
          </el-form-item>
        </el-form>
      </div>

      </el-dialog>
  
  

      <el-dialog
      class="table-dialog"
      :close-on-click-modal="false"
      :title="tableName"
        v-model="tableDio"
        width="60%"
      >
      <el-scrollbar height="650px">


      
   <div v-if='tableName.includes("粉体")'>
    <table style="line-height:20px" class="my_table" border='1px'  width="100%"  >
      <tr class="table_center">
            <td>项目名称 </td>
            <td>
            
              <el-input disabled  size="small" v-model="myTableData.proj_name" placeholder="请输入"></el-input>
            </td>
            <td>项目代号</td>
            <td> 
              
              <el-input disabled  size="small" v-model="myTableData.proj_no" placeholder="请输入"></el-input>
            </td>
            <td>专业负责人</td>
            <td> 
              
              <el-input disabled size="small" v-model="myTableData.professional_leader" placeholder="请输入"></el-input>
            
            </td>
          </tr>
       
       
        <tr class="table_center">
            <td>检查内容</td>
            <td colspan="5">
           
              <el-input type="textarea" resize="none"
              :rows="2"  size="small" v-model="myTableData.content" placeholder="请输入"></el-input>
            </td>
 
        </tr>
       <tbody v-for="(item,index) in myTableData.tableData" :key="index">
        <tr >
            <td colspan="6" class="table_font_bolder">{{Object.keys(item)[0]}}</td>
            
 
        </tr>

        <tr class="color_blue">
            <td class="table_font_bolder table_center">序号</td>
            <td class="table_font_bolder table_center" colspan="2">检查项 </td>
            <td class="table_font_bolder table_center" colspan="2">检查依据 </td>
            <td class="table_font_bolder table_center" >检查结果</td>
        </tr>

        <tr v-for="(i,index) in Object.values(item)[0]" :key="index">
            <td class="table_center">{{i['序号']}}</td>
            <td style="width:400px" colspan="2" v-html="i['检查项']"></td>
            <td style="width:200px" class="table_center" colspan="2" v-html="i['检查依据']"> </td>
            <td class="table_center" >
              <el-input type="textarea"  resize="none"
              :rows="2"  size="small" v-model="i['检查结果']" placeholder="请输入"></el-input>
            </td>
        </tr>
      </tbody>
      <tr >
            <td colspan="6" class="table_font_bolder">
              专业审核人：
              <div style="margin-top:10px">
                <el-input
                  style="width: 100%"
                  resize="none"
                  :rows="4"
                  type="textarea"
                  v-model="myTableData.reviewer1"
                  placeholder="...."
                />
              </div>
            
            </td>
            
 
        </tr>
    
      
    </table>


   </div>

   <div v-if='tableName.includes("机修")'>
    <table style="line-height:20px" class="my_table" border='1px'  width="100%"  >
      <tr class="table_center">
            <td>项目名称 </td>
            <td>
              <!-- {{myTableData.proj_name}} -->
              <el-input disabled  size="small" v-model="myTableData.proj_name" placeholder="请输入"></el-input>
            </td>
            <td>项目代号</td>
            <td> 
              <!-- {{myTableData.proj_no}} -->
              <el-input disabled  size="small" v-model="myTableData.proj_no" placeholder="请输入"></el-input>
            </td>
            <td>专业负责人</td>
            <td> 
              <!-- {{myTableData.professional_leader}} -->
              <el-input disabled size="small" v-model="myTableData.professional_leader" placeholder="请输入"></el-input>
            
            </td>
          </tr>
       
       
        <tr class="table_center">
            <td>检查内容</td>
            <td colspan="5">
           <!-- {{myTableData.content}} -->
              <el-input disabled size="small" v-model="myTableData.content" placeholder="请输入"></el-input>
            </td>
 
        </tr>
       <tbody v-for="(item,index) in  myTableData.tableData" :key="index">
        <tr >
            <td colspan="6" class="table_font_bolder">{{Object.keys(item)[0]}}</td>
            
 
        </tr>

        <tr class="color_blue">
            <td class="table_font_bolder table_center">序号</td>
            <td class="table_font_bolder table_center" colspan="2">检查项 </td>
            <td class="table_font_bolder table_center" colspan="2">检查依据 </td>
            <td class="table_font_bolder table_center" >检查结果</td>
        </tr>

        <tr v-for="(i,index) in Object.values(item)[0]" :key="index">
            <td class="table_center">{{i['序号']}}</td>
            <td style="width:400px" colspan="2" v-html="i['检查项']"></td>
            <td style="width:200px" class="table_center" colspan="2" v-html="i['检查依据']"> </td>
            <td class="table_center" >
              <el-input type="textarea"  resize="none"
              :rows="2"  size="small" v-model="i['检查结果']" placeholder="请输入"></el-input>
            </td>
        </tr>
      </tbody>
      <tr >
            <td colspan="6" class="table_font_bolder">
              专业审核人：
              <div style="margin-top:10px">
                <el-input
                  style="width: 100%"
                  resize="none"
                  :rows="4"
                  type="textarea"
                  v-model="myTableData.reviewer1"
                  placeholder="...."
                />
              </div>
            
            </td>
            
 
        </tr>
    
      
    </table>

 
   </div>


   <div v-if='tableName.includes("设备、工业炉")'>
    <table style="line-height:20px" class="my_table" border='1px'  width="100%"  >
      <tr class="table_center">
            <td>项目名称 </td>
            <td>
              <!-- {{myTableData.proj_name}} -->
              <el-input disabled  size="small" v-model="myTableData.proj_name" placeholder="请输入"></el-input>
            </td>
            <td>项目代号</td>
            <td> 
              <!-- {{myTableData.proj_no}} -->
              <el-input disabled  size="small" v-model="myTableData.proj_no" placeholder="请输入"></el-input>
            </td>
            <td>专业负责人</td>
            <td> 
              <!-- {{myTableData.professional_leader}} -->
              <el-input disabled size="small" v-model="myTableData.professional_leader" placeholder="请输入"></el-input>
            
            </td>
          </tr>
       
       
        <tr class="table_center">
            <td>检查内容</td>
            <td colspan="5">
             
           <!-- {{myTableData.content}} -->
              <el-input disabled size="small" v-model="myTableData.content" placeholder="请输入"></el-input>

           
            </td>
 
        </tr>
        
       <tbody v-for="(item,index) in myTableData.tableData" :key="index">
        <tr >
            <td colspan="6" class="table_font_bolder">{{Object.keys(item)[0]}}</td>
            
 
        </tr>

        <tr class="color_blue">
            <td class="table_font_bolder table_center">序号</td>
            <td class="table_font_bolder table_center" colspan="2">检查项 </td>
            <td class="table_font_bolder table_center" colspan="2">检查依据 </td>
            <td class="table_font_bolder table_center" >检查结果</td>
        </tr>

        <tr v-for="(i,index) in Object.values(item)[0]" :key="index">
            <td class="table_center">{{i['序号']}}</td>
            <td style="width:400px" colspan="2" v-html="i['检查项']"></td>
            <td style="width:200px" class="table_center" colspan="2" v-html="i['检查依据']"> </td>
            <td class="table_center" >
              <el-input type="textarea"  resize="none"
              :rows="2" size="small" v-model="i['检查结果']" placeholder="请输入"></el-input>
            </td>
        </tr>
      </tbody>
      <tr >
            <td colspan="6" class="table_font_bolder">
              专业审核人：
              <div style="margin-top:10px">
                <el-input
                  style="width: 100%"
                  resize="none"
                  :rows="4"
                  type="textarea"
                  v-model="myTableData.reviewer1"
                  placeholder="...."
                />
              </div>
            
            </td>
            
 
        </tr>

        <tr >
            <td colspan="6" class="table_font_bolder">
              注：安全设计完整性管理应贯穿建设项目的项目前期、工艺包设计、初步/基础工程设计、施工图/详细工程设计、施工安装和投料试车各个阶段。
         
            
            </td>
            
 
        </tr>
    
      
    </table>

 
   </div>

   
  </el-scrollbar>

  <div style="width: 100%; display: flex; flex-direction: row-reverse;margin-top:20px">
    <el-button
              type="success"
              size="small"
              @click="FinishCheck()"
              >审核通过</el-button
            >
            &nbsp;&nbsp;&nbsp;&nbsp;
              <el-button
              type="primary"
              size="small"
              @click="saveTable()"
              >保存</el-button
            >
            &nbsp;&nbsp;&nbsp;
            <el-button size="small" @click="cancelSave()">取消</el-button>
          


            </div>
      </el-dialog>

  
    </div>
  </template>
  
  <script setup name="Project">
import {Filter} from '@element-plus/icons-vue'
import JSZipUtils from "jszip-utils";
import docxtemplater from "docxtemplater";
import { saveAs } from "file-saver";
import JSZip from "pizzip";
import ImageModule from 'docxtemplater-image-module-free'
import { Plus, Delete, Warning,Upload,Tickets,CirclePlus,Download,MessageBox

} from "@element-plus/icons-vue";
  import { defineAsyncComponent, ref, reactive, onMounted, watch } from "vue";

  import { useProjectStore } from "/@/stores/project";
 
  import { useEquipmentStore } from "../../stores/equipment";
  /* 引入组件 */


  
  /* 引入API */
  import {
    UpdateStandCheckInfo,
    GetStandChecks,
    GetSafetyDesignChecklist,
    FinishStandCheckInfo,
    GetSafetyDesignCheckItems,
    UpdateSafetyDesignCheckItems,
    DeleteSafetyDesignCheckTable,
    FinishSafetyDesignCheck,
    SendSafetyDesignCheck
  } from "/@/api/equipment";

  import PinYinMatch from "pinyin-match";
  import {
  
  GetDepartmentUsersV2,
 
  
} from "../../api/projectManage/projectList";

  import { ElMessage, ElMessageBox, ElNotification } from "element-plus";
  /* 定义变量内容 */
  let selectedProject = ref({});
  const projectStore = useProjectStore();
  let EquipmentStore = useEquipmentStore();
  let equipments = ref([]);
  let tempEquipList = ref([]);
  
  let tableDatas = ref([])
  let DCdata = ref([])
  let handleSelectionChange = (data) => {
    DCdata.value = data
  }


  let newDioFrom = ref({
    proName:null,
    checkers:null,
  })


  let FinishCheck = async() => {
    saveTable('auto')
    
    let res =  await FinishSafetyDesignCheck({
      oid:myTableData.value.oid,
      currentUser:JSON.parse(localStorage.getItem("userMessage")).user_name
      
    })
    if(res=='True'){
      ElMessage({
        message: "审核成功",
        type: "success",
      })  
      getTableData({
        proj_oid:projectStore.projectInfo.proj_oid,
        currentUser:JSON.parse(localStorage.getItem("userMessage")).user_name
      },{
        majorSelect: majorSelect.value,
        check_contentSelect:[check_contentSelect.value].includes
        ('')?[]: [check_contentSelect.value]
      })
      tableDio.value = false
    }
  }


  let saveTable = async(str) => {
   
   
    let arr = []
    myTableData.value.tableData.forEach(v=>{
       arr.push(Object.values(v)[0])
    })
    
    let newArr = [].concat(...arr)
    let obj = {}
    tableName.value.includes('粉体专业')?( obj = {
      checklist_oid:myTableData.value.oid,
      check_opinion:myTableData.value.reviewer1,
      currentUser:JSON.parse(localStorage.getItem("userMessage")).user_name,
      check_content:myTableData.value.content,
      arr : newArr.map(v=>{
        return {
           "serial_number": v.serial_number,
        "check_results": v['检查结果']
        }
      })
    }):(
      obj = {
      checklist_oid:myTableData.value.oid,
      check_opinion:myTableData.value.reviewer1,
      currentUser:JSON.parse(localStorage.getItem("userMessage")).user_name,
      arr : newArr.map(v=>{
        return {
           "serial_number": v.serial_number,
        "check_results": v['检查结果']
        }
      })
    }
    )
    
    let res = await UpdateSafetyDesignCheckItems(obj)
    if(res=='True'){
      if(!str){
        ElMessage({
        message: "保存成功",
        type: "success",
      })  
      }
      
      tableDio.value = false

      getTableData({
        proj_oid:projectStore.projectInfo.proj_oid,
        currentUser:JSON.parse(localStorage.getItem("userMessage")).user_name
      },{
        majorSelect: majorSelect.value,
        check_contentSelect:[check_contentSelect.value].includes
        ('')?[]: [check_contentSelect.value]
      })
    }
    
//     if (tableName.value.includes('设备、工业炉')) {
 
// } else if (tableName.value.includes('粉体')) {

// } else if (tableName.value.includes('机修')) {

// } 


  }


  let cancelSave = () => {
    tableDio.value = false
  }


  let deleteRow =async (row) => {
    let res = await DeleteSafetyDesignCheckTable({
      checklist_oid:row.oid
    })
    if(res == 'True'){
      ElMessage({
        message: "删除成功",
        type: "success",

    })

    getTableData({
        proj_oid:projectStore.projectInfo.proj_oid,
        currentUser:JSON.parse(localStorage.getItem("userMessage")).user_name
      },{
        majorSelect: majorSelect.value,
        check_contentSelect:[check_contentSelect.value].includes
        ('')?[]: [check_contentSelect.value]
      })
    }
  }


  let myTableData = ref({
    proj_name:'',
    proj_no:'',
    professional_leader:'',
    content:'',
    tableData:[
    
      ],
    reviewer1:'',

  })

let showSelect = ref(false)





  let newDioFromRules =  ref({
    proName: [
    { required: true, message: "请选择", trigger: "change" },
  ],
  checkers: [{ required: true, message: "请选择", trigger: "change" }],

});


 let  equip_name_title = ref('')
 let proj_no_title = ref('')
  let selectable = (row, index) => {
   
   return row.check_status
  }

  
  let clickDC = async() => {
    if(DCdata.value.length == 0){
      ElMessage({
        message: "请选择一条数据",
        type: "warning",
      })
      return
    }
    
    for(let i of DCdata.value){
       
       if(i.major == "粉体专业"){
       let res = await  getExportData(i)
      
        let obj = {
          proj_no:res.proj_no,
          proj_name:res.proj_name,
          check_opinion:res.check_opinion,
          professional_leader:res.professional_leader,
          check_content:res.check_content,
        }
        
       let newArr = [].concat(...(res.SafetyDesignCheckTypes.map(v=>{
          return v.SafetyDesignCheckItems
        })))
        
        newArr.forEach(v=>{
          obj[v.serial_number] = v.check_results
        })
        
         exportWordDocx({name:'粉体专业',data:obj})
       }else if(i.major == "设备、工业炉专业"){
        let res = await  getExportData(i)

        
        let obj = {
          proj_no:res.proj_no,
          proj_name:res.proj_name,
          check_opinion:res.check_opinion,
          professional_leader:res.professional_leader,
          check_content:res.check_content,
        }
        
       let newArr = [].concat(...(res.SafetyDesignCheckTypes.map(v=>{
          return v.SafetyDesignCheckItems
        })))
        
        newArr.forEach(v=>{
          obj[v.serial_number] = v.check_results
        })
        
         exportWordDocx({name:'设备、工业炉专业',data:obj})
       
       }else if(i.major == "机修专业"){
        let res = await  getExportData(i)
        
        let obj = {
          proj_no:res.proj_no,
          proj_name:res.proj_name,
          check_opinion:res.check_opinion,
          professional_leader:res.professional_leader,
          check_content:res.check_content,
        }
        
       let newArr = [].concat(...(res.SafetyDesignCheckTypes.map(v=>{
          return v.SafetyDesignCheckItems
        })))
        
        newArr.forEach(v=>{
          obj[v.serial_number] = v.check_results
        })
        
         exportWordDocx({name:'机修专业',data:obj})
       }
    }
    
        
  }

let getExportData = async (data) => {

  let res =  await GetSafetyDesignCheckItems({
    proj_oid:projectStore.projectInfo.proj_oid,
    oid:data.oid
   })
   return res
}
  

  let exportWordDocx  = ({name, data : wordData}) => {
   
    const url = `/${name}.docx`;
    JSZipUtils.getBinaryContent(url,(err, data)=>{
      if (err) {
      ElMessage.error("导出报告出错");
      console.log("err:", err);
      return;
    }
    let zip = new JSZip(data);
    const Docxtemplater = docxtemplater;
    const imageOptions = {
      centered: false,
      getImage(tagValue, tagName) {
        return new Promise(function (resolve, reject) {
          JSZipUtils.getBinaryContent(tagValue, function (error, content) {
            if (error) {
              return reject(error);
            }
            return resolve(content);
          });
        });
      },
      getSize(img, tagValue, tagName) {
        // 非固定大小（这里是设置宽度最大为500px的图片）
        return new Promise(function (resolve, reject) {
          let image = new Image();
          image.src = tagValue;
          let imgWidth, imgHeight, scale;
          image.onload = function () {
            imgWidth = image.width;
            imgHeight = image.height;
            scale = 0;
            if (imgWidth > 500) {
              scale = 500 / imgWidth;
              imgWidth = 500;
              imgHeight = imgHeight * scale;
            }
            resolve([imgWidth, imgHeight]);
          };
          image.onerror = function (e) {
            console.log("img, tagValue, tagName : ", img, tagValue, tagName);
            reject(e);
          };
        });
      },
    };

    const nullGetter = (part, scopeManager) => {
      if (!part.module) {
        return "";
      }
    };
    let doc = new Docxtemplater(zip, {linebreaks: true,  nullGetter: nullGetter, modules: [new ImageModule(imageOptions)] });
   
    doc.resolveData({...wordData}).then(()=>{
      doc.render();
      let out = doc.getZip().generate({
        type: "blob",
        MimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
      });
      saveAs(out, `${name}- 安全审查表.docx`);
    })
  })
  }

  
  let checkFrom = ref({
    checkItem010: true,
     "checkItem020": true,
        "checkItem030": true,
        "checkItem040": true,
        "checkItem050": true,
        "checkItem060": true,
        "checkItem070": true,
        "checkItem080": true,
        "checkItem090": true,
        "checkItem100": true,
        "checkItem110": true,
        "checkItem120": true,
        "checkItem130": true,
        "checkItem140": true,
        "checkItem150": true,
        "checkItem160": true,
        "issue": null,
        "modification_status": null,
  })


  let checkFromDC = ref({
         checkItem010: true,
        "checkItem020": true,
        "checkItem030": true,
        "checkItem040": true,
        "checkItem050": true,
        "checkItem060": true,
        "checkItem070": true,
        "checkItem080": true,
        "checkItem090": true,
        "checkItem100": true,
        "checkItem110": true,
        "checkItem120": true,
        "checkItem130": true,
        "checkItem140": true,
        "checkItem150": true,
        "checkItem160": true,
        "issue": null,
        "modification_status": null,
  })
  


  
  let destEquipInfoRef = ref("");
  
  let newDio = ref(false);
  


  let checkData = ref({})
  let checkDetail = async(row) => {
   
   let res =  await GetSafetyDesignCheckItems({
    proj_oid:projectStore.projectInfo.proj_oid,
    oid:row.oid
   })


    tableName.value = `${row.major} - 安全设计检查表`
        myTableData.value.proj_name = projectStore.projectInfo.proj_name
        myTableData.value.proj_no = projectStore.projectInfo.proj_no
        myTableData.value.professional_leader = res.professional_leader
        tableName.value.includes('粉体专业')?(
          myTableData.value.content = res.check_content
        ):(
          myTableData.value.content = row.check_content
        )
       
        myTableData.value.oid = row.oid
        myTableData.value.reviewer1 = res.check_opinion
        myTableData.value.tableData = res.SafetyDesignCheckTypes.map(v=>{
            return {
             
              [v.TypeName]:v['SafetyDesignCheckItems'].map(item=>{
                return {
                  ...item,
                  ['序号']: item.serial_number,
                  ['检查项']: item.check_item,
                  ['检查依据']: item.inspection_basis,
                  ['检查结果']: item.check_results
                }
              })
              
            }
          })



        tableDio.value = true

  }
  

  let sendDataCheckOptions_py = ref([])
  let matchFruit = (searchContent) => {
    if (searchContent) {
    let result = [];
    sendDataCheckOptions.value.forEach((item) => {
      // matchResult 的值为 true/false
      let matchResult = PinYinMatch.match(item.label, searchContent);
      if (matchResult) {
        result.push(item);
      }
    });
    sendDataCheckOptions_py.value = result;
  } else {
    sendDataCheckOptions_py.value = sendDataCheckOptions.value;
  }
  }

 
  let majorSelect = ref([])
  let check_contentSelect  = ref('')
  watch([majorSelect,check_contentSelect],()=>{
    
    getTableData({
        proj_oid:projectStore.projectInfo.proj_oid,
        currentUser:JSON.parse(localStorage.getItem("userMessage")).user_name
      },{
        majorSelect: majorSelect.value,
        check_contentSelect:[check_contentSelect.value].includes
        ('')?[]: [check_contentSelect.value]
      })
  })





  

  let activeHeight = ref(0);



  
  const handleClick = (tab, event) => {
    console.log(tab, event);
  };
  
  let unit_oidOptions = ref([]);

  let approverOptions = ref([])
  let auditorOptions = ref([])
  let equip_designerOptions = ref([])
  let equip_checkerOptions = ref([])
  let SelectEquip_no = ref([]);
  let equipEquip_no = ref([]);
  
  let SelectEquip_class = ref([]);
  let equipEquip_class = ref([]);
  


  let getTableData =async (data,obj) => {
   let res = await GetSafetyDesignChecklist(data)
  
   let data1 = res.filter(v=>!v.check_status)
   let data2 = res.filter(v=>v.check_status)

   const filters = {
    major: obj.majorSelect, // num 符合 'R1' 或 'R2'
    check_content: obj.check_contentSelect, // id 符合 1
  
  };
  
   let dataORG = [...data1,...data2]
   tableDatas.value = multiFilter(JSON.parse(JSON.stringify(dataORG)), filters);
  }



  function multiFilter(array, filters) {
  const filterKeys = Object.keys(filters);

  return array.filter((item) => {
    return filterKeys.every((key) => {
      if (!filters[key].length) return true;
     
      return !!~(item[key]? item[key] : []).indexOf(filters[key]);
    });
  });
}


  watch(
    () => projectStore.projectInfo,
    (newVal, oldVal) => {
      selectedProject.value = newVal;
      getTableData({
        proj_oid:projectStore.projectInfo.proj_oid,
        currentUser:JSON.parse(localStorage.getItem("userMessage")).user_name
      },{
        majorSelect: majorSelect.value,
        check_contentSelect:[check_contentSelect.value].includes
        ('')?[]: [check_contentSelect.value]
      })
    },{immediate:true}
  );
  
  let SelectMajor = ref([]);
  let equipOptions = ref([]);
  
  let equip_nameInput = ref([]);
  let nameOptions = ref([]);

  /* 定义生命周期函数 */
  onMounted(() => {
    activeHeight.value =
    document.querySelector(".project-container").clientHeight - 100;
  window.addEventListener("resize", () => {
    activeHeight.value =
      document.querySelector(".project-container").clientHeight - 100;
  });


  

  });


  // 自定义排序函数
let customSort = (a, b) => {
  // 判断 a 和 b 是否含有字母 R
  var aHasR = a.equip_version.includes("R");
  var bHasR = b.equip_version.includes("R");

  // 如果 a 和 b 都含有字母 R
  if (aHasR && bHasR) {
    // 提取 R 后的数字并转换为整数进行比较
    var aNum = parseInt(a.equip_version.substr(1));
    var bNum = parseInt(b.equip_version.substr(1));
    return bNum - aNum;
  }
  // 如果 a 和 b 都不含有字母 R
  else if (!aHasR && !bHasR) {
    // 直接比较字符串大小
    var aNum2 = parseInt(a.equip_version, 10);
    var bNum2 = parseInt(b.equip_version, 10);

    return bNum2 - aNum2;
  }
  // 如果一个含有字母 R，一个不含有
  else {
    // 含有字母 R 的排在前面
    return aHasR ? -1 : 1;
  }
};

  let EquipNoArr = ref([])

  let newDioFn =async () => {
    newDio.value = true
    newDioFrom.value.proName = '粉体专业'

    let res = await GetDepartmentUsersV2({ dept: "equipment" })
    sendDataCheckOptions.value = res.map(v=>{
     return {
      label:v.user_name,
      value:v.user_name
     }
    })
    sendDataCheckOptions_py.value = sendDataCheckOptions.value
  }

  let tableName = ref('')
  let tableDio = ref(false)

 let newDioFromRef = ref(null)
  let newDioFnSubmit = (formEl) => {
    if (!formEl) return;
    formEl.validate(async (valid) => {
      if (valid) {
      
        let res =  await SendSafetyDesignCheck(
  projectStore.projectInfo.proj_oid,
  '粉体专业',
  newDioFrom.value.checkers,
  JSON.parse(localStorage.getItem("userMessage")).user_name,
  []
)
if(res == 'True'){
  getTableData({
        proj_oid:projectStore.projectInfo.proj_oid,
        currentUser:JSON.parse(localStorage.getItem("userMessage")).user_name
      },{
        majorSelect: majorSelect.value,
        check_contentSelect:[check_contentSelect.value].includes
        ('')?[]: [check_contentSelect.value]
      })
      ElMessage({ message: "新建成功", type: "success" });
      newDio.value = false
}

   
      }

    })
    
  }

  let cancelButtonText = (formEl) => {
    newDio.value = false
    formEl.resetFields();
  }

  let sendDataCheckOptions = ref([])

  </script>
  
  <style scoped lang="scss">
  
  .text_{
    padding: 10px;
  }
  .flex_alitenm{
    span{
      width: 54%;
      font-size: 12px;
      margin-right:10px ;
    }
    display: flex;
    margin-bottom: 10px;
    align-items: center;
  }
  .project-infor-cards {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
  }
  
  .equip-list {
    min-height: calc(100vh - 170px);
    background-color: #fff;
  }
  
  .equip-title_span {
    font-weight: bold;
    margin-right: auto;
    font-size: 1.5em;
    padding-left: 8px;
    border-left: 6px solid #67c23a;
  }
  .equip-buttons {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 8px;
    margin-bottom: 8px;
  
    .el-button-group {
      display: flex;
      align-items: center;
  
      margin-left: 16px;
    }
  }
  
  .demo-tabs > .el-tabs__content {
    padding: 32px;
    color: #6b778c;
    font-size: 32px;
    font-weight: 600;
  }
  .img_hualu{
    position: absolute;
      transform: scale(0.5) rotate(0deg);
      top: -13px;
      right: -102px;
      z-index: 88;
      opacity: .7;
  }
  .card-header{
    font-size: 25px;
    font-weight: bolder;
  }


  ::v-deep(.table-dialog){
    text-align: center;
  }

  .my_table {
  
  flex-wrap: wrap;

    text-align: left;
border-collapse:collapse;
tr{
 
  width: 100%;
}
td{
 
  padding: 8px 24px;
  font-size: 12px;
}
.table_font_bolder{
  font-weight: bold;
}
.table_center{
text-align: center
}
.color_blue{
  background:#c6d9f1;
}
}
  </style>
  